import axios from 'axios'

// create an axios instance

const service = axios.create({
    baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
    // withCredentials: true, // send cookies when cross-domain requests
    timeout: 10000 // request timeout
})

// 返回其他状态吗
service.defaults.validateStatus = function(status) {
    return status >= 200 && status <= 500 // 默认的
}

// request interceptor
service.interceptors.request.use(
    config => {
        console.log('---------请求前---------------')
        console.log('---------请求前---------------')
        return config
    },
    error => {
        console.log(error) // for debug
        return Promise.reject(error)
    }
)

// response interceptor
service.interceptors.response.use(
    response => {
        const res = response.data
        console.log('--------response.data----------')
        console.log(res)
        console.log(response)
        console.log('--------response.data----------')
    },
    error => {
        console.log('err' + error) // for debug
        return Promise.reject(error)
    }
)

export default service
